code refactor, minor fixes