Cleaned up pinning function