Trying to write slightly better code