finished sub code