Removed duplication, and unused code