Working but could be refactored sligtly