Multiple bugs fixed (still needs revision)