Core refactoring. Added comments.