refactoring this into something proper