seems to be working now, needs lots of testing