taken output formatting out of main script and also added tests so this thing is actually useful =P