Refactor of core

 - Get rid of mutual recursion
 - Use generator
 - Implements doctype
 - Fix licence