Added memory functions and modified main().