Added transaction and repeated code removed