updating implementation to be more elegant.