fixed bunch of bugs