Implemented partition subroutine