Cleaned up code, commented, and it seems to work