Cleaned The code and fixed some problems