Added clear(), fixed some wrong code and added coding style.