Various fixes, updating style, cleaning up code