Commited various bugfixes and added test