got it working, still needs to be refactored