Bring code in to line with coding guidelines and correct bugs