Refactor, minor fixes