Updated with Emergya's modifications