Refactored the basic code as skeleton for future use