refactor code a little