added docs, fixed various bugs, see readme.md