cleaned up debug code
added gradient fix to more files