Move functionality into separate functions