refactored everything. not working correctly yet