Code reformatted and debugged