refactor code a bit