Some bugs fixed; first functional version