How were the walls in Attack on Titan built? If I remember correctly, in Attack on Titan, it's mentioned or implied a number of times that humans built the walls to protect themselves from the titans. (Feel free to correct me if I'm wrong on this.) If so then, how did they manage to get the walls erected (which seem to be the result of somewhat extensive work) without getting killed, if they were already under attack by that point?

(Note: I'm only about halfway through the anime series, so I might just be missing something that appears later.)
Spoilers from the manga.

After the king's sanctum incident (ch50~65) 


   (when Rod Reiss tried to make Historia eat Eren), 


it is disclosed that


   The First King used his Coordinate power (control over titans) to force those titans to use their hardening power to shape up the walls, then used his Memory power to wipe the memories from the pre-wall era from humanity. 


Why did he 


   leave hibernating titans inside the walls


is unknown.


   he also created the Wallist Church to help him oversee the walls safety.