Added some signal synchronisation and fixed a logical bug;
Got rid of all the remaining compilation warnings