Slightly better version with additional tests