refactor functions a bit