added code from Ir1sh's commit