Refactor / bug fix

Signed-off-by: Diwank Singh <diwank.singh@gmail.com>
Refactors

Signed-off-by: Diwank Singh <diwank.singh@gmail.com>
Added tests

Signed-off-by: Diwank Singh <diwank.singh@gmail.com>