refactored and commented pose management code