update sin with Mika's solution, feel free to compare my ugly solution in comment