mostly functional. needs testing.