Fixed bunch of bugs