fixing multithreading issues and stdin issues, some mockup code is in there