Removed duplicated code and fix for failing test