#21 a few bug fixes, needs more testing