Fixed several bugs that were discussed in the last meeting, still need t...

...o work on the sample files