slight alterations, fixed a few bugs, added one preprocessing step