Mainly functions from Programming Collective Intelligence

Added/adding own personal touches