Made the code more readable, more bug fixed