Some refactoring to make it pretty. ;O)