fixed some bugs for linux at least
now works in most of the cases