refactored a bit, this will work for now