Changes to make code more idiomatic; also fix command-line handler