restructuring and lots of comments added