using ajdawson's better code. Added tests for each axis