Refactored a little bit