Final refactoring after getting comments from Steve