Added AutoMapper support. Refactored code