moved code execution on separate thread (when possible) and fixed small code bugs