Move sig logic and fork logic to function calls
Refactor code