ugly code working