Some code re-writing