working subroutine printing and removed segfaults