Removed code duplication
Use sprintf for cleaner code