Some big refactor. CASE and IF not so bad now.