Cleaned and optimized Core code