recoded and optimized for awesomeness