Added test + bugfixes