Cleaned up code, updated comments