Refactored begintransaction for performance

Change-Id: I0eb58f8b1620036345b0992b78cb6ba4285b6df5