Refactor format, fix issues