Simplified the code as per Admin comment.