Refactor code and remove unused commented code