Refactored to look more decent