Major update based on the work from Rabbitman and Maxine