refactor functionality