Small fixes for threads etc as suggested by Aby