Code Re-factoring

Change the expression to be encapsulated into logical function.