Added scheduler; fixed some bugs