Refactoring

@slajax - refactored this and added validations.