added new code for better performance (hopefully)