Update patch based on Gerd's comments and fixing other minor problems