Some fixes according to the comments by @ monarchdodra