Cleaned stuff up

Consolidated existing code and removed redundant code.