Fix #2

Also minor code cleanup