Some internal restructuring
Added lexer; some bugfixes