Cleaned up code for better perfs