Updated version and thanks to Jason Toy