Improved previous implementation