code review, removed some unneeded brackets, simplify some functions