Refactor code, add missing core functionality.