split out handle into its own file, refactor context to use new handle logic