refactor code for nicer reading