Cleanup and bug fix (thanks to @andreiciubotariu for spotting it)