Improved performance and added logging