Final final fix + cleanup of code