Cleaned up code, implemented #4 and fixed #1