refactor thx ursm and macchima23