still needs a bit of cleanup and tests