Checked for Alpha 5 compatibility + some rewriting