Do some code cleanup. Separate interface from implementation in core.