Fix #160 and rearrange a few things