Corrected the partnership code and a few optimizations