Fixed several small bugs