Attempted some optimizations. Not working currently