quick refactor of code from identified issue on codeclimate