More general and bug fixes for choosing package version