added some corrections und debugging messages, still buggy