Added support for reinstallation and downgrades

This pull request adds support for package reinstallation and downgrades and fixes one minor issue.