Attempted some minor speed improvements after some runtime analysis