Fixed many small bugs