Refactored to my needs