refactor, finished core part