Fix several small bugs