refactor, still not working yet tho