Fixed errors and started rewriting