Add/fix export to apkg functionality

Expose and fix the export to apkg functionality, also some formatting cleanup.