Code logic and style changes