found the bug, rudimentary working version