Use consistent missing value
Move key functionality into separate functions for readability