Implemented deque:nth and some refactoring and cleanup.