removed unused functions and add debugging messages