Refactor, scripts i used so far for research and minor fixes.