moved some code form shputil to app for better coherency.