fixed #1, fixed #2 and fixed #4 + debug output