big refactor, should work now!!