Fixed #5, other bugfixes