Removed unused functions.
Refactored some code.