made more robust
fixed output, removed debugging