rewrote before script