First attempt to abstract the code.