Simplifying some code