extracted copypasta'd code to common library and added rest of clean command