Refactored code and added comments

Change-Id: Ifa06bfd07291f4e46c4adaaaaa98642538a56edc
Signed-off-by: jonathan <joshsolutionsltd@gmail.co>