Fix typos
Fix typos and rewrite weird code