fixed major bug and implemented small improvements