Completed formatting and fixed bug on flag placement after edge case