Logger added. Debug info added. Small fixes and improvements.