Made functionality more robust