I have updated the code to fix a few bugs that Роман Д. pointed out. Thank you Роман! Download the latest version here.