updated and separated into two files