So, I've made a new version and will be submitting a pull request now.  Yes, there are some terrible if statements in here.  I have done the best I can (well, very close to the best I can) in getting rid of repeated code and the unnecessary boolean madness.  Unfortunately, I couldn't find a way around some booleans, so please if anyone has suggestions, send them my way (on the next pull request- this one is, well, bad).