Added some additional if defined checks to improve compatibility