Make tilray init() handle large numbers properly
Fix some (not all) leaks found by valgrind.
Fixed so % always works on positive numbers
Merge memory leaks and rotation fix.