code improvements and updated test