Implement package cache and fix bugs in package resolution