Added code reuse and small fixes