Split up pkg into multiple files & cleanup code