Code refactor as per comments