Added some functions and encountered bug

Some functions are present in multiple versions to easier spot the bug.
more info in todo.txt