lots of minor changes in code, added some functionality