Clearer code and add test