Some debug statements added and minor bug fixes.