Some refactorying to make things more readable