Fixed all kinds of bugs