adding bulk of the code -- may need to add some other odd things here and there later