*another* major refactor; hope this changes are used this time