Updated functionality and cleaned up code