Merge duplicate code and posted below.