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