Fixed numerous small bugs