Cleaned up code and commented methods for transparency