Fixed the termination of the program. Added some docs