Refactor to use more custom functions; introduce the ternary operator (i...

...n comments)