added lots of things from the old working version