Minor bugfixes and unittesting introduction.