Code tidy up

Removes some cruft and improves readability. @incuna/js please.