Cloned from Jah PowerBIt's awesome implementation