Refactor code a little bit