Added a format function
bug fixes