Cleaned up all the code and added lost of comments