Code reformatted and restructured