Added togglePin() and refactored the rest of the code accordingly.