cleaned up and commented a bit