Cleaned up core and made it more readable