added some code to check for zero-length values (to avoid errors during runtime)