removed dead code and simplified implementation