fixed multiple bugs. Fixes #1