Solved the layout problem and added some error checking