Resolve compile errors and refactor packages