Comments added and code cleaned up