I have not tested if these work, but I made minimal changes to them (only things like comments and newlines).