modified according to zacc and bebef1987's suggestion