Cleaned up code slightly