Added more comments and deleted global variables