Fixes for many issues

All errors mentioned in #23 are now fixed.