Corrected version
Added testing function