Some bugfixes and improvements, it seems to be working now.