Bugfixing and working implementation of CustomModel.
Clean up code.