Refactor of dirty stuff
Doc to Markdown
More refactor and fixed minor bugs