Modified according to zacc's suggestion