Removed dead code and simplified code.